<template>
  <div class="main-body">
    <a-layout id="components-layout-demo-custom-trigger">
      <a-layout-sider v-model="collapsed" :trigger="null" collapsible>
        <div class="logo">热度管理</div>
        <a-menu theme="dark" :default-selected-keys="['home']" mode="inline">
          <a-menu-item key="home">
            <router-link to="/home">
              <span>
                <a-icon type="home" />
                <span>首页</span>
              </span>
            </router-link>
          </a-menu-item>
          <a-menu-item key="goods">
            <router-link to="/goods">
              <span>
                <a-icon type="shop" />
                <span>商品列表</span>
              </span>
            </router-link>
          </a-menu-item>
          <a-menu-item key="order" v-if="userState">
            <router-link to="/order">
              <span>
                <a-icon type="desktop" />
                <span>订单管理</span>
              </span>
            </router-link>
          </a-menu-item>
          <a-sub-menu :default-selected-keys="['user']">
            <span slot="title"
              ><a-icon type="lock" /><span>权限管理</span></span
            >
            <a-menu-item key="user">
              <router-link to="/user"> 用户管理 </router-link>
            </a-menu-item>
            <a-menu-item key="role">
              <router-link to="/role"> 角色管理 </router-link>
            </a-menu-item>

            <a-menu-item key="notice">
              <router-link to="/notice"> 公告管理 </router-link>
            </a-menu-item>
          </a-sub-menu>
        </a-menu>
      </a-layout-sider>
      <a-layout>
        <a-layout-header style="background: #fff; padding: 0" class="myheader">
          <a-icon
            class="trigger"
            :type="collapsed ? 'menu-unfold' : 'menu-fold'"
            @click="() => (collapsed = !collapsed)"
          />

          <div class="btn-box">
            <div>
              <a-avatar :size="46" icon="user" />
              当前权限等级：{{ this.$store.state.state }}
            </div>

            <a-button type="danger" @click="loginOut"> 安全退出 </a-button>
          </div>
        </a-layout-header>
        <a-layout-content
          :style="{
            margin: '24px 16px',
            padding: '24px',
            background: '#fff',
            minHeight: '280px',
          }"
        >
          <slot name="route-view"></slot>
        </a-layout-content>
      </a-layout>
    </a-layout>
  </div>
</template>

<script >
import Cookies from "js-cookie";
export default {
  data() {
    return {
      collapsed: false,
      userState: null,
    };
  },
  methods: {
    loginOut() {
      Cookies.remove("id");
      Cookies.remove("token");
      this.$router.push("/");
    },
  },
  created() {
    // console.log(navList);
    // this.userState = this.$store.state.state;
    // console.log(this.userState);
    if (this.$store.state.state > 2) {
      this.userState = false;
    } else {
      this.userState = true;
    }
  },
};
</script>
<style scoped>
.logo {
  text-align: center;
  color: white;
  font-size: 20px;
  overflow: hidden;
}
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
}
#components-layout-demo-custom-trigger {
  height: 100vh;
  width: 100vw;
}
.main-body {
  height: 100vh;
  width: 100vw;
}
.myheader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-box {
  width: 300px;
  height: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
</style>
